package Netty之NIO背景.selector;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * @author ChenweiLin
 * @create 2021-12-07 15:48
 */
public class WriteClient {
    public static void main(String[] args) throws IOException {
        SocketChannel sc = SocketChannel.open();
        sc.connect(new InetSocketAddress(8080));

        //3.接收数据
        int count = 0;
        ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
        while (true){
            count += sc.read(buffer);//sc.read(buffer)方法返回值为读到的字节
            System.out.println(count);
            buffer.clear();
        }
    }
}
